﻿#include "SLT_tcpSender.h"
#include "TcpServerImpl.h"

#define  _CACTCPPROT_LOG_DEBUG(_format,...)  SLT_LOG_DEBUG("[TCPSER]" _format, ##__VA_ARGS__)
#define  _CACTCPPROT_LOG_INFO(_format,...)  SLT_LOG_DEBUG("[TCPSER]" _format, ##__VA_ARGS__)
#define  _CACTCPPROT_LOG_ERR(_format,...)  SLT_LOG_ERR("[TCPSER]" _format, ##__VA_ARGS__)
CCacTcpServer* CCacTcpServer::getInst()
{
	static CCacTcpServerSptr s_server;
	if (!s_server) {
		s_server = std::make_shared< CCacTcpServer>();
	}
	return s_server.get();
}
int CCacTcpServer::init(int port)
{
	SLT_setTcpRecvMsgCb(std::bind(&CCacTcpServer::recvTcpMsgCB,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,
	                                    std::placeholders::_4,std::placeholders::_5,std::placeholders::_6));
	m_tcpserver = sl_createTcpServer();
	m_tcpserver->init(this);
	m_tcpserver->start();
	return 0;
}
void CCacTcpServer::TcpServer_onConnect(SLTcpClientPtr& _client)
{
	//作为客户端，没有这个通知
}
void CCacTcpServer::recvTcpMsgCB(uint32_t _dstID, int msgid, uint32_t _srcID,
                    SLF_sendMemBasePtr& _data,const SLF_senderPtr & _senderPtr,SLF_SessionBasePtr &_in_out_sessSptr)
{
	//接收消息分配session
}

SLF_senderPtr  CCacTcpServer::getProxyCfgSender(const std::string& _rip, uint16_t _rport, bool reuse)
{
	//获取代理管理sender
	SLTcpClientPtr tcpcli = m_tcpserver->createClient();
	return SLT_getTcpClientSender(tcpcli,_rip,_rport,reuse);
}
